|
|
 |
|
|
|
|
Dim i As Integer
Dim next_time As Long
' Get the current time. next_time = GetTickCount
' Start the animation. For i = 0 To NumImages 1 ' Display the next frame. picCanvas.Picture = picFrame(i).Picture
NumPlayed = NumPlayed + 1
' Wait till we should display the next frame. next_time = next_time + ms_per_frame
WaitTill next_time
If Not Playing Then Exit For
Next i
End Sub |
|
|
|
|
|
|
|
|
Example program PlayWait uses this code to display a series of images. In one test on a 133MHz Pentium processor, the program displayed 385 frames per secondalmost as many frames as program PlayFast described earlier. This technique allows a program close to the best speed possible while giving precise control of the animation speed. |
|
|
|
|
|
|
|
|
Displaying Files Directly |
|
|
|
|
|
|
|
|
Programs PlayFast, PlayTmr, and PlayWait all load their frame bitmaps into hidden picture box controls. That lets them display the frame quickly because they are already loaded into memory. |
|
|
|
|
|
|
|
|
Unfortunately, this also means they must have all the images loaded into memory at the same time. A simple animation might contain 100 frames, each holding a 250 by 250 pixel bitmap. If the bitmaps use 8-bit color, the images take 100 * 250 * 250 * 1, or more than 6MB of memory. If the bitmaps use 24-bit color, the images require more than 18MB of memory. Larger images would require even more memory. |
|
|
|
|
|
|
|
|
This memory requirement can be a problem. If the program uses too much memory, the system may run out of physical memory. In that case, it must page files to disk, and that slows the entire system dramatically. |
|
|
|
|
|
|
|
|
An alternative to all this memory use is to display the files as they are loaded using LoadPicture. Only one frame is loaded at a time, so the program uses much less memory. On the other hand, this method relies on the speed of the LoadPicture function reading files from the hard disk. Hard disks are much slower than memory, so this method reduces the maximum number of frames the program can display per second. |
|
|
|
|
|
|
|
|
Example program PlayFile demonstrates this approach. While programs PlayFast and PlayWait displayed more than 380 frames per second on a 133MHz Pentium processor, |
|
|
|
|
|